var timestamp = new Date().getTime();
layui.config({
    version:'1510164124181'
}).use(['form','laydate', 'laypage', 'layer', 'element'],function(){
    form = layui.form;
    layer = layui.layer;
    laydate = layui.laydate;//日期
    laypage = layui.laypage;//分页
    element = layui.element; //元素操作


    // /**实现功能，保存用户的登录信息到cookie中。当登录页面被打开时，就查询cookie**/
    var tokenUser = getCookieValue("token");
    var username = getCookieValue("username");
    if (tokenUser!=null && tokenUser!="") {
        sessionStorage.setItem("username",username);
        window.location.href="indexs.html";
    }
    $(".codeimg img").attr("src",httpurl+"/userverification?"+timestamp);
    $(".codeimg img").click(function () {
        timestamp = new Date().getTime();
        $(this).attr('src',$(this).attr('src') + '?' +timestamp );
    })
});

function keyLogin(event) {
    if (event.keyCode == 13)document.getElementById("entry").click();
}

function check_logon() {
    var  adminName=$("#adminName").val();
    var  adminPwd=$("#adminPwd").val();
    var code=$("#code").val();
    var isCk=0;
    if(!$("#chkRememberPass").is(":checked")){
        isCk=1;
    }
    $.ajax({
        type:"POST",
        url: httpurl+"/findUserName",
        cache: false,
        data: {
           "username":adminName,
            "password":adminPwd,
            "code":code,
            "isCk":isCk
        },
        success: function (data) {
            //调用  加密
            var pwd=Base64.encode(adminPwd+"_1512350");
            if(data.rtnCode==200){
                if (isCk==0) {
                    addCookie("isCk", isCk, 1, "/");
                    addCookie("password", pwd, 1, "/");
                    addCookie("token", data.msg, 1, "/");
                    addCookie("username", adminName, 1, "/");
                }else {
                    addCookie("isCk", isCk, 7, "/");
                    addCookie("password", adminPwd,7, "/");
                    addCookie("token", data.msg, 7, "/");
                    addCookie("username", adminName, 7, "/");
                }
                window.location.href="indexs.html";
            }else {
                layer.msg(data.msg);
                timestamp = new Date().getTime();
                $(".codeimg img").attr("src",httpurl+"/userverification?"+timestamp);
            }
        },error:function (data) {
            layer.msg("读取接口失败,请稍后再试试");
        }
    })
}
